﻿using UnityEngine;
using System.Collections;
using System;

public class ImageLoader  {
    public static ImageLoader mInstance { get; private set; }

    public static ImageLoader getInstance() {
        if(mInstance==null) {
            mInstance = new ImageLoader();
        }
        return mInstance;
    }
    public void load(UITexture obj, String url) {
        Debug.Log("obj " + obj);
        Debug.Log("url " + url);

        obj.StartCoroutine(loadImage(obj, url));
        
    }

    IEnumerator loadImage(UITexture obj, String url) {
        WWW www = new WWW(url);
        yield return www;
        Texture2D txt2d = new Texture2D(4, 4, TextureFormat.RGBA4444, true);
        www.LoadImageIntoTexture(txt2d);
        //Resources.LoadAssetAtPath("http://u3dchina.com/template/singcere_dw/common/images/logo.png", typeof(Texture)) as Texture;
        obj.mainTexture = txt2d;
    }

}
